(function(){
	angular.module('app').factory('PagerService', PagerService);

	PagerService.$inject = ['$timeout'];

	function PagerService($timeout){

		var realPagination = {
            begin: 0,
            count: 10,           
            pageCount: 10000,
            currentPage: 0,
            setAllPageCount: function(_pageCount){
            	console.log('setAllPageCount');

            	if(this.pageCount === Math.ceil(_pageCount/this.count)){
            		return;
            	}
				this.pageCount = Math.ceil(_pageCount/this.count);        	
            	
            },
            onPageChange: function() {

                this.begin = (this.currentPage - 1) * this.count;
                //在具体的使用页中设置分页的函数，function pagerChange (){}
                this.pagerChange();
            }
        };

		return {
			
			init:init

		};

		function init(config){

			var pageCopy = angular.copy(realPagination);

			if(typeof config === 'object'){

				pageCopy = angular.extend(pageCopy,config);

			}else{

				console.log('初始化配置 config 是json类型或者不配置');

			}

			

			return pageCopy;
		}
	}
})();